#ifndef I2C_H
#define I2C_H
#include "at32f403a_407_clock.h"
#include "i2c_application.h"
 
#define write 0
#define read  1

#define I2C2_TIMEOUT                      0xFFFFFFFF

#define I2C2x_SPEED                       100000
#define I2C2x_ADDRESS                     0xA0

#define I2C2x_PORT                        I2C2
#define I2C2x_CLK                         CRM_I2C2_PERIPH_CLOCK

#define I2C2x_SCL_PIN                     GPIO_PINS_10
#define I2C2x_SCL_GPIO_PORT               GPIOB
#define I2C2x_SCL_GPIO_CLK                CRM_GPIOB_PERIPH_CLOCK

#define I2C2x_SDA_PIN                     GPIO_PINS_11
#define I2C2x_SDA_GPIO_PORT               GPIOB
#define I2C2x_SDA_GPIO_CLK                CRM_GPIOB_PERIPH_CLOCK

#define BUF_SIZE                         8

#define MASTER_BOARD
#define I2C_FSMODE_DUTY_2_1                   0x00
 
//IIC总线地址接口定义
#define IIC_SCL_H  GPIOB->scr = GPIO_PINS_10
#define IIC_SCL_L  GPIOB->clr = GPIO_PINS_10
#define IIC_SDA_OUT_H   GPIOB->scr = GPIO_PINS_11
#define IIC_SDA_OUT_L   GPIOB->clr = GPIO_PINS_11

#define IIC_SDA_IN    GPIOB->idt&GPIO_PINS_11
 
#define IIC_INPUT_MODE_SET()  { GPIOB->cfghr&=0xFFFF0FFF;GPIOB->cfghr|=0x00008000;}
#define IIC_OUTPUT_MODE_SET() {GPIOB->cfghr&=0xFFFF0FFF;GPIOB->cfghr|=0x00003000;}
 
//函数声明
void IIC_Init(void);
void IIC_START(void);
void IIC_STOP(void);
u8 IIC_GetACK(void);
void IIC_SendAck(u8 ack);
void IIC_WriteOneByte(u8 data);
u8 IIC_ReadOneByte(void);
void i22c_lowlevel_init(i2c_handle_type* hi22c);
#endif


